package com.xbh.boot_study.util;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * @ResponseData: resp
 * @author: ZBoHang
 * @time: 2022/3/16 9:14
 */
@Data
@Accessors(chain = true)
public class ResponseData<T> implements Serializable {

    private String code;

    private String msg;

    private T data;

    public ResponseData() {
    }

    private ResponseData(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static ResponseData<String> failure(String msg) {

        return new ResponseData<String>().setCode("500").setMsg(msg);
    }

    public static ResponseData failure() {

        return new ResponseData().setCode("500").setMsg("失败");
    }

    public static <T> ResponseData<T> success() {

        return new ResponseData<T>().setCode("200").setMsg("suc!");
    }

    public static <T> ResponseData<T> success(T data) {

        return new ResponseData<T>().setCode("200").setMsg("suc!").setData(data);
    }
}
